﻿Imports System.Data
Imports System.Data.SqlClient

Public Class GenCode

#Region "Var"
    Private AutoNumber As Boolean
    Private mData As DataTable
   
    Private tblName As String
    Private ColName() As String
    Private ColType() As String
    Private DataType() As String
    Private PrimaryKey() As Boolean
    Private PrimaryKeyCount As Integer = 0
    Private Leng As Integer
    Private _namesp As String = ""
    Private _connString As String = ""
#End Region

#Region "Constructor"
    Private Function IsPrimary(ByVal col As String, ByVal pk As DataTable) As Boolean
        For i As Integer = 0 To pk.Rows.Count - 1
            If col = pk.Rows(i)(0) Then
                Return True
            End If
        Next


        Return False
    End Function

    Private Function LoadAllField(ByVal tablename As String) As DataTable
        Dim strSQL As String = "SELECT A.name, B.name As typeName, A.length, B.length As sizeLength, A.Autoval " _
                        + " FROM SysColumns A, SysTypes B, SysObjects C " _
                        + " WHERE A.id=C.id AND A.xtype=B.xtype AND B.name<>'sysname' " _
                        + " AND C.name='" + tablename + "' ORDER BY A.ColOrder"

        Dim da As New SqlDataAdapter(strSQL, _connString)
        Dim dt As New DataTable
        da.Fill(dt)
        Return dt
    End Function

    Private Function DanhSach(ByVal tablename As String) As DataTable
        Dim strSQL As String = "SELECT column_name as 'Column Name', data_type as 'Data Type', character_maximum_length FROM information_schema.columns WHERE table_name = '" + tblName + "' "

        Dim da As New SqlDataAdapter(strSQL, _connString)
        Dim dt As New DataTable
        da.Fill(dt)
        Return dt
    End Function

    Private Function LoadPrimaryKey(ByVal tablename As String) As DataTable
        Dim strSQL As String = "select c.name " _
                        + " from sysindexes i " _
                        + " join sysobjects o ON i.id = o.id " _
                        + " join sysobjects pk ON i.name = pk.name " _
                        + " AND pk.parent_obj = i.id " _
                        + " AND pk.xtype = 'PK' " _
                        + " join sysindexkeys ik on i.id = ik.id " _
                        + " and i.indid = ik.indid  " _
                        + " join syscolumns c ON ik.id = c.id  " _
                        + " AND ik.colid = c.colid  " _
                        + " where o.name = '" + tablename + "'  " _
                        + " order by ik.keyno"

        Dim da As New SqlDataAdapter(strSQL, _connString)
        Dim dt As New DataTable
        da.Fill(dt)
        Return dt
    End Function

    Public Sub New(ByVal tablename As String, ByVal _namespace As String, ByVal connstring As String)
        _namesp = _namespace
        _connString = connstring
        tblName = tablename
        mData = LoadAllField(tablename)
        Dim pk As DataTable = LoadPrimaryKey(tablename)
        Leng = mData.Rows.Count
        ReDim ColName(mData.Rows.Count - 1)
        ReDim ColType(mData.Rows.Count - 1)
        ReDim PrimaryKey(mData.Rows.Count - 1)
        ReDim DataType(mData.Rows.Count - 1)
        Dim i As Integer
        For i = 0 To Leng - 1
            ColName(i) = mData.Rows(i)("name")
            ColType(i) = mData.Rows(i)("typeName")
            DataType(i) = mData.Rows(i)("typeName")
            If ColType(i) = "bigint" Then ColType(i) = "long"
            If ColType(i) = "smallint" Then ColType(i) = "byte"
            If ColType(i) = "datetime" Then ColType(i) = "DateTime"
            If ColType(i) = "float" Then ColType(i) = "double"
            If ColType(i) = "bit" Then ColType(i) = "bool"
            If (ColType(i) = "char" Or ColType(i) = "nchar" Or _
                ColType(i) = "varchar" Or ColType(i) = "nvarchar" _
                Or ColType(i) = "ntext" Or ColType(i) = "ntext") Then ColType(i) = "string"
        Next

        'mData1 = DanhSach(tablename)
        ''Dim j As Integer
        'For i = 0 To Leng - 1
        '    DataType1(i) = mData1.Rows(i)("character_maximum_length")
        'Next

        If pk.Rows.Count = 0 Then
            PrimaryKey(0) = True
            PrimaryKeyCount = 1
        Else
            For i = 0 To Leng - 1
                PrimaryKey(i) = IsPrimary(ColName(i), pk)
                If PrimaryKey(i) Then PrimaryKeyCount += 1
            Next
        End If

        AutoNumber = False
        For i = 0 To Leng - 1
            If Not mData.Rows(i)("Autoval") Is DBNull.Value Then AutoNumber = True
        Next
    End Sub
#End Region

#Region "sub Function"

    Private Function Header1() As String
        Dim code As String = ""
        code += "-- ==========================================================================" + vbCrLf
        code += "-- Author : CanhHungIT" + vbCrLf
        code += "-- Created Date : " + Now.ToLongDateString() + vbCrLf
        code += "-- ==========================================================================" + vbCrLf + vbCrLf + vbCrLf
        Return code
    End Function

    Private Function Header() As String
        Dim code As String = ""
        code += "//---------------------------------------------------------------------------" + vbCrLf
        code += "// Author : CanhHungIT" + vbCrLf
        code += "// Created Date : " + Now.ToLongDateString() + vbCrLf
        code += "//---------------------------------------------------------------------------" + vbCrLf + vbCrLf + vbCrLf
        Return code
    End Function

    Private Function GetInitValue(ByVal coltype As String) As String
        Select Case coltype.ToLower()
            Case "long"
                Return "0"
            Case "int"
                Return "0"
            Case "byte"
                Return "0"
            Case "double"
                Return "0"
            Case "float"
                Return "0"
            Case "object"
                Return "null"
            Case "string"
                Return """""" ' hai dau nhay ""
            Case "bool"
                Return "false"
            Case "datetime"
                Return "DateTime.Now"
        End Select
        Return """"""
    End Function

    Private Function new1Info() As String
        Dim code As String = ""
        code += vbTab + vbTab + "public " + tblName + "_Entities()" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf
        Return code
    End Function

    Private Function new1_DAL() As String
        Dim code As String = ""
        code += vbTab + vbTab + "public " + tblName + "_DAL(){}" + vbCrLf
        Return code
    End Function

    Private Function new1_BLL() As String
        Dim code As String = ""
        code += vbTab + vbTab + "public " + tblName + "_BLL(){}" + vbCrLf
        Return code
    End Function

    Private Function Insert_BLL() As String
        Dim code As String = ""
        code += vbTab + vbTab + "public int Insert(" + _namesp + "_Entities." + tblName + "_Entities p)" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + "return obj.Insert(p);" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function Insert_GUI() As String
        Dim code As String = ""
        Dim i As Integer
        code += vbTab + vbTab + "public int Insert()" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + _namesp + "_Entities." + tblName + "_Entities p =new " + _namesp + "_Entities." + tblName + "_Entities();" + vbCrLf
        code += vbTab + vbTab + vbTab + "int result = 0;" + vbCrLf
        code += vbTab + vbTab + vbTab + "try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf

        For i = 0 To Leng - 1
            If mData.Rows(i)("Autoval") Is DBNull.Value Then       ' a[0] = "@SoChungThu";
                'code += vbTab + vbTab + vbTab + vbTab + "a[" + i.ToString() + "] = ""@" + ColName(i) + """;" + vbCrLf
                code += vbTab + vbTab + vbTab + vbTab + "p." + ColName(i) + "=" + GetInitValue(ColType(i)) + ";" + vbCrLf
                'code += vbTab + vbTab + vbTab + vbTab + "param.Add(new DataParameter(""@" + ColName(i) + """, p." + ColName(i) + "));" + vbCrLf
            End If
        Next
        code += vbTab + vbTab + vbTab + vbTab + "result = obj.Insert(p);" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch(Exception ex)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "throw ex;" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "if (result > 0)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "MessageBox.Show(" + """" + "Add Success!" + """" + ");" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "else" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "MessageBox.Show(" + """" + "Error! Please try again" + """" + ");" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "return result;" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function Load_DL_GUI() As String
        Dim code As String = ""
        Dim i As Integer
        code += vbTab + vbTab + "public  void load_Dl_Form()" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + "DataTable dt = new DataTable();" + vbCrLf
        code += vbTab + vbTab + vbTab + _namesp + "_BLL." + tblName + "_BLL obj =new " + _namesp + "_BLL." + tblName + "_BLL();" + vbCrLf
        code += vbTab + vbTab + vbTab + _namesp + "_Entities." + tblName + "_Entities p =new " + _namesp + "_Entities." + tblName + "_Entities();" + vbCrLf
        For i = 0 To Leng - 1
            If PrimaryKey(i) Then
                code += vbTab + vbTab + vbTab + "p." + ColName(i) + " = " + ColName(i) + ";" + vbCrLf
            End If
        Next
        code += vbTab + vbTab + vbTab + "dt = obj.SelectByID(p);" + vbCrLf
        ' code += vbTab + vbTab + vbTab + "int result = 0;" + vbCrLf


        code += vbTab + vbTab + vbTab + "foreach (DataRow dr in dt.Rows)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf

        For i = 0 To Leng - 1
            If mData.Rows(i)("Autoval") Is DBNull.Value Then       ' a[0] = "@SoChungThu";
                'code += vbTab + vbTab + vbTab + vbTab + "a[" + i.ToString() + "] = ""@" + ColName(i) + """;" + vbCrLf
                code += vbTab + vbTab + vbTab + vbTab + ColName(i) + "=" + "dr[" + """" + ColName(i) + """" + "].ToString();" + vbCrLf
                'code += vbTab + vbTab + vbTab + vbTab + "param.Add(new DataParameter(""@" + ColName(i) + """, p." + ColName(i) + "));" + vbCrLf
            End If
        Next
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += BindControl()

        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function Update_GUI() As String
        Dim code As String = ""
        Dim i As Integer
        code += vbTab + vbTab + "public int Update()" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + _namesp + "_Entities." + tblName + "_Entities p =new " + _namesp + "_Entities." + tblName + "_Entities();" + vbCrLf
        code += vbTab + vbTab + vbTab + "int result = 0;" + vbCrLf
        code += vbTab + vbTab + vbTab + "try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        For i = 0 To Leng - 1
            If mData.Rows(i)("Autoval") Is DBNull.Value Then       ' a[0] = "@SoChungThu";
                'code += vbTab + vbTab + vbTab + vbTab + "a[" + i.ToString() + "] = ""@" + ColName(i) + """;" + vbCrLf
                code += vbTab + vbTab + vbTab + vbTab + "p." + ColName(i) + "=" + GetInitValue(ColType(i)) + ";" + vbCrLf
                'code += vbTab + vbTab + vbTab + vbTab + "param.Add(new DataParameter(""@" + ColName(i) + """, p." + ColName(i) + "));" + vbCrLf
            End If
        Next
        code += vbTab + vbTab + vbTab + vbTab + "result = obj.Update(p);" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch(Exception ex)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "throw ex;" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "if (result > 0)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "MessageBox.Show(" + """" + "Update Success" + """" + ");" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "else" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "MessageBox.Show(" + """" + "Error! Please try again" + """" + ");" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf

        code += vbTab + vbTab + vbTab + "return result;" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function Del_GUI() As String
        Dim code As String = ""
        Dim i As Integer
        code += vbTab + vbTab + "public int Delete()" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + _namesp + "_Entities." + tblName + "_Entities p = new " + _namesp + "_Entities." + tblName + "_Entities();" + vbCrLf
        code += vbTab + vbTab + vbTab + "int result = 0;" + vbCrLf
        code += vbTab + vbTab + vbTab + "try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        For i = 0 To Leng - 1
            If PrimaryKey(i) Then       ' a[0] = "@SoChungThu";
                'code += vbTab + vbTab + vbTab + vbTab + "a[" + i.ToString() + "] = ""@" + ColName(i) + """;" + vbCrLf
                code += vbTab + vbTab + vbTab + vbTab + "p." + ColName(i) + "=" + GetInitValue(ColType(i)) + ";" + vbCrLf
                'code += vbTab + vbTab + vbTab + vbTab + "param.Add(new DataParameter(""@" + ColName(i) + """, p." + ColName(i) + "));" + vbCrLf
            End If
        Next
        code += vbTab + vbTab + vbTab + vbTab + "result = obj.Delete(p);" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch(Exception ex)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "throw ex;" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "if (result > 0)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "MessageBox.Show(" + """" + "Delete Success" + """" + ");" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "else" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "MessageBox.Show(" + """" + "Error! Please try again" + """" + ");" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "return result;" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function Load_GUI() As String
        Dim code As String = ""
        Dim i As Integer
        code += vbTab + vbTab + "public DataTable SelectByID()" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + _namesp + "_Entities." + tblName + "_Entities p =new " + _namesp + "_Entities." + tblName + "_Entities();" + vbCrLf
        code += vbTab + vbTab + vbTab + "DataTable result = new DataTable();" + vbCrLf
        code += vbTab + vbTab + vbTab + "try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        For i = 0 To Leng - 1
            If PrimaryKey(i) Then       ' a[0] = "@SoChungThu";
                'code += vbTab + vbTab + vbTab + vbTab + "a[" + i.ToString() + "] = ""@" + ColName(i) + """;" + vbCrLf
                code += vbTab + vbTab + vbTab + vbTab + "p." + ColName(i) + "=" + GetInitValue(ColType(i)) + ";" + vbCrLf
                'code += vbTab + vbTab + vbTab + vbTab + "param.Add(new DataParameter(""@" + ColName(i) + """, p." + ColName(i) + "));" + vbCrLf
            End If
        Next
        code += vbTab + vbTab + vbTab + vbTab + "result = obj.SelectByID(p);" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch(Exception ex)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "throw ex;" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "return result;" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function LoadTable_GUI() As String
        Dim code As String = ""
        'Dim i As Integer
        code += vbTab + vbTab + "public DataTable SelectAll()" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + "DataTable result = new DataTable();" + vbCrLf
        code += vbTab + vbTab + vbTab + "try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "result = obj.SelectAll();" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch(Exception ex)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "throw ex;" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "return result;" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function Insert_Store() As String
        'Dim datalength1() As String = DataTypeLength()
        Dim code As String = ""
        Dim i As Integer
        code += vbTab + "if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[" + tblName + "_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + vbCrLf
        code += vbTab + "drop table [dbo].[" + tblName + "_Insert]" + vbCrLf
        code += vbTab + "GO" + vbCrLf
        code += vbTab + "CREATE PROCEDURE " + tblName + "_Insert" + vbCrLf
        ' AutoNumber = False
        For i = 0 To Leng - 2


            If mData.Rows(i)("Autoval") Is DBNull.Value Then

                code += vbTab + "@" + ColName(i) + " " + DataType(i) + " " + DataType.Length.ToString() + "," + vbCrLf
            End If

        Next
        code += vbTab + "@" + ColName(Leng - 1) + " " + mData.Rows(i)("typeName") + vbCrLf
        code += vbTab + "AS" + vbCrLf
        code += vbTab + "INSERT INTO " + tblName + " ("
        For i = 0 To Leng - 2
            If mData.Rows(i)("Autoval") Is DBNull.Value Then
                code += ColName(i) + ", "
            End If
        Next
        code += ColName(Leng - 1) + ") " + vbCrLf + vbTab + " VALUES ("
        For i = 0 To Leng - 2
            If mData.Rows(i)("Autoval") Is DBNull.Value Then
                code += "@" + ColName(i) + ", "
            End If
        Next
        code += "@" + ColName(Leng - 1) + ")" + vbCrLf
        code += "Go" + vbCrLf + vbCrLf + vbCrLf + vbCrLf
        'code = code.Remove(code.Length - 2, 2)
        Return code
    End Function

    Private Function Insert() As String
        Dim code As String = ""
        Dim i As Integer
        'code += vbTab + vbTab + "private const string " + tblName + "_Insert = ""INSERT INTO " + tblName + " ("
        'For i = 0 To Leng - 2
        '    If mData.Rows(i)("Autoval") Is DBNull.Value Then
        '        code += ColName(i) + ", "
        '    End If
        'Next
        'code += ColName(Leng - 1) + ") """ + vbCrLf + vbTab + vbTab + " + "" VALUES ("
        'For i = 0 To Leng - 2
        '    If mData.Rows(i)("Autoval") Is DBNull.Value Then
        '        code += "@" + ColName(i) + ", "
        '    End If
        'Next
        'code += "@" + ColName(Leng - 1) + ")"";" + vbCrLf
        code += vbTab + vbTab + "public int Insert(" + _namesp + "_Entities." + tblName + "_Entities p)" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + "int result = " + Leng.ToString() + ";" + vbCrLf
        code += vbTab + vbTab + vbTab + "try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        'Dim hung As String = Convert.ToString(Leng - 2)

        'code += vbTab + vbTab + vbTab + vbTab + "int so = " + (Leng).ToString() + ";" + vbCrLf

        If AutoNumber Then
            code += vbTab + vbTab + vbTab + vbTab + "SqlParameter[] sParam = new SqlParameter[]" + vbCrLf
            code += vbTab + vbTab + vbTab + vbTab + "{" + vbCrLf
            For i = 0 To Leng - 2
                If mData.Rows(i)("Autoval") Is DBNull.Value Then
                    code += vbTab + vbTab + vbTab + vbTab + vbTab + "new SqlParameter(""@" + ColName(i) + """, p." + ColName(i) + ")," + vbCrLf
                End If
            Next
            code += vbTab + vbTab + vbTab + vbTab + vbTab + "new SqlParameter(""@" + ColName(Leng - 1) + """, p." + ColName(Leng - 1) + ")" + vbCrLf
        Else
            code += vbTab + vbTab + vbTab + vbTab + "SqlParameter[] sParam = new SqlParameter[]" + vbCrLf
            code += vbTab + vbTab + vbTab + vbTab + "{" + vbCrLf
            For i = 0 To Leng - 2
                If mData.Rows(i)("Autoval") Is DBNull.Value Then
                    code += vbTab + vbTab + vbTab + vbTab + vbTab + "new SqlParameter(""@" + ColName(i) + """, p." + ColName(i) + ")," + vbCrLf
                End If
            Next
            code += vbTab + vbTab + vbTab + vbTab + vbTab + "new SqlParameter(""@" + ColName(Leng - 1) + """, p." + ColName(Leng - 1) + ")" + vbCrLf
        End If
        code += vbTab + vbTab + vbTab + vbTab + "};" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "result = obj.UpdateData(" + """" + tblName + "_Insert" + """" + ", sParam);" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch(Exception ex)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "throw ex;" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "return result;" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function Update_BLL() As String
        Dim code As String = ""
        code += vbTab + vbTab + "public int Update(" + _namesp + "_Entities." + tblName + "_Entities p)" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + "return obj.Update(p);" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function Update_store() As String
        Dim code As String = ""
        Dim i As Integer
        code += vbTab + "CREATE PROCEDURE " + tblName + "_Update" + vbCrLf

        For i = 0 To Leng - 2
            If mData.Rows(i)("Autoval") Is DBNull.Value Then
                code += vbTab + "@" + ColName(i) + " " + mData.Rows(i)("typeName") + "," + vbCrLf
            End If
        Next
        code += vbTab + "@" + ColName(Leng - 1) + " " + mData.Rows(i)("typeName") + vbCrLf
        code += vbTab + "AS" + vbCrLf

        code += vbTab + vbTab + "UPDATE " + tblName + " SET " + vbCrLf
        For i = 0 To Leng - 1
            If Not PrimaryKey(i) Then
                code += vbTab + vbTab + vbTab + ColName(i) + " = @" + ColName(i) + "," + vbCrLf
            End If
        Next
        code = code.Substring(0, code.Length - 5) + vbCrLf
        code += vbTab + vbTab + vbTab + " WHERE ("
        For i = 0 To Leng - 1
            If PrimaryKey(i) Then
                code += ColName(i) + " = @" + ColName(i) + ") AND ("
            End If
        Next
        code = code.Substring(0, code.Length - 6) + vbCrLf
        code += "Go" + vbCrLf + vbCrLf + vbCrLf + vbCrLf
        Return code
    End Function

    Private Function Update() As String
        Dim code As String = ""
        Dim i As Integer

        'code += vbTab + vbTab + "private const string UPDATE_" + tblName + " = ""UPDATE " + tblName + " SET """ + vbCrLf
        'For i = 0 To Leng - 1
        '    If Not PrimaryKey(i) Then
        '        code += vbTab + vbTab + vbTab + " + "" " + ColName(i) + " = @" + ColName(i) + ", """ + vbCrLf
        '    End If
        'Next
        'code = code.Substring(0, code.Length - 5) + " """ + vbCrLf
        'code += vbTab + vbTab + vbTab + " + "" WHERE ("
        'For i = 0 To Leng - 1
        '    If PrimaryKey(i) Then
        '        code += ColName(i) + " = @" + ColName(i) + ") AND ("
        '    End If
        'Next
        'code = code.Substring(0, code.Length - 6) + """;" + vbCrLf

        code += vbTab + vbTab + "public int Update(" + _namesp + "_Entities." + tblName + "_Entities p)" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + "int result = " + Leng.ToString() + ";" + vbCrLf
        code += vbTab + vbTab + vbTab + "try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf

        If AutoNumber Then
            code += vbTab + vbTab + vbTab + vbTab + "SqlParameter[] sParam = new SqlParameter[]" + vbCrLf
            code += vbTab + vbTab + vbTab + vbTab + "{" + vbCrLf
            For i = 0 To Leng - 2
                If mData.Rows(i)("Autoval") Is DBNull.Value Then
                    code += vbTab + vbTab + vbTab + vbTab + vbTab + "new SqlParameter(""@" + ColName(i) + """, p." + ColName(i) + ")," + vbCrLf
                End If
            Next
            code += vbTab + vbTab + vbTab + vbTab + vbTab + "new SqlParameter(""@" + ColName(Leng - 1) + """, p." + ColName(Leng - 1) + ")" + vbCrLf
        Else
            code += vbTab + vbTab + vbTab + vbTab + "SqlParameter[] sParam = new SqlParameter[]" + vbCrLf
            code += vbTab + vbTab + vbTab + vbTab + "{" + vbCrLf
            For i = 0 To Leng - 2
                If mData.Rows(i)("Autoval") Is DBNull.Value Then
                    code += vbTab + vbTab + vbTab + vbTab + vbTab + "new SqlParameter(""@" + ColName(i) + """, p." + ColName(i) + ")," + vbCrLf
                End If
            Next
            code += vbTab + vbTab + vbTab + vbTab + vbTab + "new SqlParameter(""@" + ColName(Leng - 1) + """, p." + ColName(Leng - 1) + ")" + vbCrLf
        End If
        code += vbTab + vbTab + vbTab + vbTab + "};" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "result = obj.UpdateData(" + """" + tblName + "_Update" + """" + ", sParam);" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch(Exception ex)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "throw ex;" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "return result;" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function GetIndexPrimary(ByVal count As Integer) As Integer
        For i As Integer = 0 To Leng - 1
            If PrimaryKey(i) Then
                count -= 1
                If count = -1 Then Return i
            End If
        Next
        Return -1
    End Function

    Private Function Del_BLL() As String
        Dim code As String = ""
        Dim i As Integer
        code += vbTab + vbTab + "public int Delete("
        For i = 0 To Leng - 1
            If PrimaryKey(i) Then  '+ tblName + "Info my" + tblName +
                code += _namesp + "_Entities." + tblName + "_Entities p, "
            End If
        Next
        code = code.Substring(0, code.Length - 2) + ")" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + " return obj.Delete(p);" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function Del() As String
        Dim code As String = ""
        Dim i As Integer

        'code += vbTab + vbTab + "private const string DELETE_" + tblName + " = ""DELETE FROM " + tblName + " WHERE ("
        'For i = 0 To Leng - 1
        '    If PrimaryKey(i) Then
        '        code += ColName(i) + " = @" + ColName(i) + ") AND ("
        '    End If
        'Next
        'code = code.Substring(0, code.Length - 6) + """;" + vbCrLf

        code += vbTab + vbTab + "public int Delete("
        For i = 0 To Leng - 1
            If PrimaryKey(i) Then  '+ tblName + "Info my" + tblName +
                code += _namesp + "_Entities." + tblName + "_Entities p, "
            End If
        Next
        code = code.Substring(0, code.Length - 2) + ")" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf

        code += vbTab + vbTab + vbTab + "int result = 1;" + vbCrLf
        code += vbTab + vbTab + vbTab + "try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "SqlParameter[] sParam = new SqlParameter[]" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "{" + vbCrLf
        For i = 0 To PrimaryKeyCount - 1
            Dim idx As Integer = GetIndexPrimary(i)
            If idx <> -1 Then
                code += vbTab + vbTab + vbTab + vbTab + vbTab + "new SqlParameter(""@" + ColName(idx) + """, p." + ColName(idx) + ")" + vbCrLf
            End If
        Next
        code += vbTab + vbTab + vbTab + vbTab + "};" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "result = obj.UpdateData(" + """" + tblName + "_Delete" + """" + ",sParam);" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch(Exception ex)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "throw ex;" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "return result;" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function Convert() As String
        Dim code As String = ""
        Dim i As Integer

        code += vbTab + vbTab + "public " + tblName + "Info Converting(DataRow dr" + tblName + ")" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + "" + tblName + "Info result = null;" + vbCrLf
        code += vbTab + vbTab + vbTab + "try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "result = new " + tblName + "Info();" + vbCrLf
        For i = 0 To Leng - 1
            code += vbTab + vbTab + vbTab + vbTab + "if(dr" + tblName + "[""" + ColName(i) + """] != DBNull.Value)" + vbCrLf
            code += vbTab + vbTab + vbTab + vbTab + vbTab
            Select Case ColType(i)
                Case "bool"
                    code += "result." + ColName(i) + " = Convert.ToBoolean(dr" + tblName + "[""" + ColName(i) + """]);" + vbCrLf
                Case "int"
                    code += "result." + ColName(i) + " = Convert.ToInt32(dr" + tblName + "[""" + ColName(i) + """]);" + vbCrLf
                Case "long"
                    code += "result." + ColName(i) + " = Convert.ToInt64(dr" + tblName + "[""" + ColName(i) + """]);" + vbCrLf
                Case "short"
                    code += "result." + ColName(i) + " = Convert.ToInt16(dr" + tblName + "[""" + ColName(i) + """]);" + vbCrLf
                Case "decimal"
                    code += "result." + ColName(i) + " = Convert.ToDecimal(dr" + tblName + "[""" + ColName(i) + """]);" + vbCrLf
                Case "double"
                    code += "result." + ColName(i) + " = Convert.ToDouble(dr" + tblName + "[""" + ColName(i) + """]);" + vbCrLf
                Case "float"
                    code += "result." + ColName(i) + " = Convert.ToDouble(dr" + tblName + "[""" + ColName(i) + """]);" + vbCrLf
                Case "DateTime"
                    code += "result." + ColName(i) + " = Convert.ToDateTime(dr" + tblName + "[""" + ColName(i) + """]);" + vbCrLf
                Case Else
                    code += "result." + ColName(i) + " = Convert.ToString(dr" + tblName + "[""" + ColName(i) + """]);" + vbCrLf
            End Select
        Next
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch(Exception ex)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "throw ex;" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "return result;" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function Load_BLL() As String
        Dim code As String = ""
        Dim i As Integer
        code += vbTab + vbTab + "public DataTable SelectByID("
        For i = 0 To Leng - 1
            If PrimaryKey(i) Then
                code += _namesp + "_Entities." + tblName + "_Entities p, "
            End If
        Next
        code = code.Substring(0, code.Length - 2) + ")" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + " return obj.SelectByID(p);" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function Load() As String
        Dim code As String = ""
        Dim i As Integer

        'code += vbTab + vbTab + "private const string " + tblName + "_SelectByID = ""SELECT * FROM " + tblName + " WHERE ("
        'For i = 0 To Leng - 1
        '    If PrimaryKey(i) Then 'tblName + "Info my" + tblName
        '        code += ColName(i) + " = @" + ColName(i) + ") AND ("
        '    End If
        'Next
        'code = code.Substring(0, code.Length - 6) + """;" + vbCrLf

        code += vbTab + vbTab + "public DataTable SelectByID("
        For i = 0 To Leng - 1
            If PrimaryKey(i) Then
                code += _namesp + "_Entities." + tblName + "_Entities p, "
            End If
        Next
        code = code.Substring(0, code.Length - 2) + ")" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf

        code += vbTab + vbTab + vbTab + "DataTable result = null;" + vbCrLf
        code += vbTab + vbTab + vbTab + "try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "SqlParameter[] sParam = new SqlParameter[]" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "{" + vbCrLf
        For i = 0 To PrimaryKeyCount - 1
            Dim idx As Integer = GetIndexPrimary(i)
            If idx <> -1 Then
                code += vbTab + vbTab + vbTab + vbTab + vbTab + "new SqlParameter(""@" + ColName(idx) + """, p." + ColName(idx) + ")" + vbCrLf
            End If
        Next
        code += vbTab + vbTab + vbTab + vbTab + "};" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "result = obj.LoadData( " + """" + tblName + "_SelectByID" + """" + ", sParam);" + vbCrLf

        'code += vbTab + vbTab + vbTab + vbTab + "DataTable dt = DataFactory.SelectTable(LOAD_" + tblName + ", param);" + vbCrLf
        'code += vbTab + vbTab + vbTab + vbTab + "if(dt.Rows.Count > 0) result = Converting(dt.Rows[0]);" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch(Exception ex)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "throw ex;" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "return result;" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function LoadTable_BLL() As String
        Dim code As String = ""
        code += vbTab + vbTab + "public DataTable SelectAll()" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf

        code += vbTab + vbTab + vbTab + " return obj.SelectAll();" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function LoadTable() As String
        Dim code As String = ""

        'code += vbTab + vbTab + "private const string LOAD_LIST_" + tblName + " = ""SELECT * FROM " + tblName + """;" + vbCrLf
        code += vbTab + vbTab + "public DataTable SelectAll()" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + "DataTable result = null;" + vbCrLf
        code += vbTab + vbTab + vbTab + "try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "result = obj.LoadData(" + """" + tblName + "_SelectAll" + """" + ");" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch(Exception ex)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "throw ex;" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "return result;" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        Return code
    End Function

    Private Function ClassTable() As String
        Dim code As String = ""
        Dim i As Integer
        code += "// Khai bao lop" + vbCrLf
        code += "using System;" + vbCrLf
        code += "using System.Data.Entity;" + vbCrLf
        code += "using System.Collections.Generic;" + vbCrLf
        code += "using System.Linq;" + vbCrLf
        code += "using System.Web;" + vbCrLf + vbCrLf
        code += "namespace " + _namesp + vbCrLf + "{" + vbCrLf
        code += vbTab + "public class " + tblName + vbCrLf
        code += vbTab + "{" + vbCrLf


        code += vbTab + vbTab + "// Cac bien so" + vbCrLf
        code += vbTab + vbTab + "#region Vars" + vbCrLf
        For i = 0 To Leng - 1
            code += vbTab + vbTab + "public " + ColType(i) + " " + ColName(i) + " { get; set; }" + vbCrLf
            'code += vbTab + vbTab + "private " + ColType(i) + " " + ColName(i) + " = " + GetInitValue(ColType(i)) + ";" + vbCrLf
        Next
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf

        ' Đóng Class
        code += vbTab + "}" + vbCrLf

        code += vbTab + "public class WebSiteConnectionString:DbContext" + vbCrLf
        code += vbTab + "{" + vbCrLf

        code += vbTab + vbTab + "#region Vars" + vbCrLf
        code += vbTab + vbTab + "public DbSet<" + tblName + "> " + tblName + "s { get; set; }" + vbCrLf
        'code += vbTab + vbTab + "private " + ColType(i) + " " + ColName(i) + " = " + GetInitValue(ColType(i)) + ";" + vbCrLf

        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf

        ' Đóng Class
        code += vbTab + "}" + vbCrLf
        code += "}" + vbCrLf + vbCrLf + vbCrLf
        Return code
    End Function
#End Region

#Region "main Function"
    Public Function GetInfo() As String
        Dim code As String = Header()
        Dim i As Integer
        code += "// Khai bao lop" + vbCrLf
        code += "using System;" + vbCrLf + vbCrLf
        code += "namespace " + _namesp + "_Entities" + vbCrLf + "{" + vbCrLf
        code += vbTab + "public class " + tblName + "_Entities" + vbCrLf
        code += vbTab + "{" + vbCrLf

        code += vbTab + vbTab + "// Ham khoi tao khong tham so" + vbCrLf
        code += vbTab + vbTab + "#region Constructor" + vbCrLf
        code += new1Info()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf

        code += vbTab + vbTab + "// Cac bien so" + vbCrLf
        code += vbTab + vbTab + "#region Vars" + vbCrLf
        For i = 0 To Leng - 1
            code += vbTab + vbTab + "private " + ColType(i) + " _" + ColName(i) + " = " + GetInitValue(ColType(i)) + ";" + vbCrLf
        Next
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf


        code += vbTab + vbTab + "#region Property" + vbCrLf
        code += vbTab + vbTab + "// Cac thuoc tinh" + vbCrLf
        For i = 0 To mData.Rows.Count - 1
            code += vbTab + vbTab + "public " + ColType(i) + " " + ColName(i) + vbCrLf
            code += vbTab + vbTab + "{" + vbCrLf
            code += vbTab + vbTab + vbTab + "get{ return _" + ColName(i) + "; }" + vbCrLf

            code += vbTab + vbTab + vbTab + "set{ _" + ColName(i) + " = value; }" + vbCrLf
            code += vbTab + vbTab + "}" + vbCrLf
        Next
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf

        ' Đóng Class
        code += vbTab + "}" + vbCrLf
        code += "}" + vbCrLf + vbCrLf + vbCrLf
        Return code
    End Function

    Public Function Get_Chuoi() As String
        Dim code As String = Header()
        code += "// Khai bao lop" + vbCrLf
        code += "using System;" + vbCrLf
        code += "using System.Linq;" + vbCrLf
        code += "using System.Text;" + vbCrLf
        code += "using System.Data;" + vbCrLf
        code += "using System.Data.SqlClient;" + vbCrLf
        code += "using System.Collections;" + vbCrLf
        code += "namespace " + _namesp + "_DAL" + vbCrLf + "{" + vbCrLf
        code += vbTab + "public class KetNoi" + vbCrLf
        code += vbTab + "{" + vbCrLf
        'code += vbTab + vbTab + "// Ham khoi tao khong tham so" + vbCrLf
        code += vbTab + vbTab + "#region Mo Ket Noi" + vbCrLf


        code += vbTab + vbTab + " private SqlConnection con;" + vbCrLf
        code += vbTab + vbTab + " public string strERR = """";" + vbCrLf
        code += vbTab + vbTab + " public void MoKetNoi()" + vbCrLf
        code += vbTab + vbTab + " {" + vbCrLf
        Dim hung As String = frmGen.txtConnection.Text
        code += vbTab + vbTab + vbTab + "string chuoikn=@" + """" + hung + """" + ";" + vbCrLf
        code += vbTab + vbTab + vbTab + "//string chuoikn = ConfigurationManager.ConnectionStrings[""WebSiteConnectionString""].ConnectionString;" + vbCrLf
        code += vbTab + vbTab + vbTab + "con = new SqlConnection(chuoikn);" + vbCrLf
        code += vbTab + vbTab + vbTab + "Try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "if (con.State == ConnectionState.Closed)" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + vbTab + "con.Open();//Mo Ket Noi" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch (Exception)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf + vbCrLf

        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + " }" + vbCrLf + vbCrLf

        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "#region Dong Ket Noi" + vbCrLf


        code += vbTab + vbTab + " public void DongKetNoi()" + vbCrLf
        code += vbTab + vbTab + " {" + vbCrLf
        code += vbTab + vbTab + vbTab + "con.Close();//Dong Ket Noi" + vbCrLf
        code += vbTab + vbTab + vbTab + "con.Dispose();" + vbCrLf
        code += vbTab + vbTab + " }" + vbCrLf + vbCrLf

        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "#region Ham Xu Ly" + vbCrLf
        code += vbTab + vbTab + "public DataTable LoadData(string sql)" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + "MoKetNoi();" + vbCrLf
        code += vbTab + vbTab + vbTab + "DataTable dt = new DataTable();" + vbCrLf
        code += vbTab + vbTab + vbTab + "try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "SqlCommand command = new SqlCommand(sql, con);" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "command.CommandType = CommandType.StoredProcedure;" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "SqlDataAdapter adapter = new SqlDataAdapter(command);" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "adapter.Fill(dt);" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "DongKetNoi();" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch (Exception e)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "DongKetNoi();" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "return dt;" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf


        code += vbTab + vbTab + "public DataTable LoadData(string Storedname, SqlParameter[] Parmeterarray)" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + "MoKetNoi();" + vbCrLf
        code += vbTab + vbTab + vbTab + "DataTable dt = new DataTable();" + vbCrLf
        code += vbTab + vbTab + vbTab + "try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "SqlCommand command = new SqlCommand(Storedname, con);" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "command.CommandType = CommandType.StoredProcedure;" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "command.Parameters.AddRange(Parmeterarray);" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "command.CommandTimeout = 100;" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "SqlDataAdapter adapter = new SqlDataAdapter(command);" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "adapter.Fill(dt);" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "DongKetNoi();" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch (Exception e)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "DongKetNoi();" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "strERR = e.Message;" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "return dt;" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf


        code += vbTab + vbTab + "private int result;" + vbCrLf
        code += vbTab + vbTab + "public int UpdateData(string sql)" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + "int result=2;" + vbCrLf
        code += vbTab + vbTab + vbTab + "MoKetNoi();" + vbCrLf
        code += vbTab + vbTab + vbTab + "SqlCommand command = new SqlCommand(sql, con);" + vbCrLf
        code += vbTab + vbTab + vbTab + "command.CommandType = CommandType.StoredProcedure;" + vbCrLf
        code += vbTab + vbTab + vbTab + "try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "result= command.ExecuteNonQuery();" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "DongKetNoi();" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch (Exception e)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "DongKetNoi();" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "strERR = e.Message;" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "return result;" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf


        code += vbTab + vbTab + "private int result1;" + vbCrLf
        code += vbTab + vbTab + "public int UpdateData(string Storedname,SqlParameter[] Parmeterarray)" + vbCrLf
        code += vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + "MoKetNoi();" + vbCrLf
        code += vbTab + vbTab + vbTab + "DataTable dt = new DataTable();" + vbCrLf
        code += vbTab + vbTab + vbTab + "try" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "SqlCommand command = new SqlCommand(Storedname, con);" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "command.CommandType = CommandType.StoredProcedure;" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "command.Parameters.AddRange(Parmeterarray);" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "command.CommandTimeout = 100;" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "result1= command.ExecuteNonQuery();" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "DongKetNoi();" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "catch (Exception e)" + vbCrLf
        code += vbTab + vbTab + vbTab + "{" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "DongKetNoi();" + vbCrLf
        code += vbTab + vbTab + vbTab + vbTab + "strERR = e.Message;" + vbCrLf
        code += vbTab + vbTab + vbTab + "}" + vbCrLf
        code += vbTab + vbTab + vbTab + "return result1;" + vbCrLf
        code += vbTab + vbTab + "}" + vbCrLf + vbCrLf

        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + "}" + vbCrLf
        code += "}" + vbCrLf + vbCrLf + vbCrLf
        Return code
    End Function

    Public Function GetDAL() As String
        Dim code As String = Header()
        code += "// Khai bao lop" + vbCrLf
        code += "using System;" + vbCrLf
        code += "using System.Collections;" + vbCrLf
        code += "using System.Data;" + vbCrLf
        code += "using System.Data.SqlClient;" + vbCrLf
        code += "using " + _namesp + "_Entities ;//Add reference vao" + vbCrLf
        code += "namespace " + _namesp + "_DAL" + vbCrLf + "{" + vbCrLf
        code += vbTab + "public class " + tblName + "_DAL" + vbCrLf
        code += vbTab + "{" + vbCrLf

        code += vbTab + vbTab + "// Ham khoi tao khong tham so" + vbCrLf
        code += vbTab + vbTab + "#region Constructor" + vbCrLf
        code += new1_DAL()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "private " + _namesp + "_DAL.KetNoi obj= new " + _namesp + "_DAL.KetNoi();" + vbCrLf
        code += vbTab + vbTab + "#region Function" + vbCrLf

        code += vbTab + vbTab + "#region Insert" + vbCrLf
        code += vbTab + vbTab + "// Insert" + vbCrLf
        code += Insert()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "#region Update" + vbCrLf
        code += vbTab + vbTab + "// Update" + vbCrLf
        code += Update()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "#region Del" + vbCrLf
        code += vbTab + vbTab + "// Del" + vbCrLf
        code += Del()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "#region SelectByID" + vbCrLf
        ' Get Info
        'code += Convert()
        code += vbTab + vbTab + "// SelectByID" + vbCrLf
        code += Load()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "#region SelectALL" + vbCrLf
        code += vbTab + vbTab + "// SelectALL" + vbCrLf
        code += LoadTable()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        ' Check Exist
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "// Dong Class" + vbCrLf
        code += vbTab + "}" + vbCrLf
        code += "}" + vbCrLf + vbCrLf + vbCrLf
        Return code
    End Function

    Public Function GetGUI() As String
        Dim code As String = Header()
        Dim i As Integer
        code += "// Khai bao lop" + vbCrLf
        code += "using System;" + vbCrLf
        code += "using System.Collections;" + vbCrLf
        code += "using System.Data;" + vbCrLf
        code += "using " + _namesp + "_Entities;//Add reference vao" + vbCrLf
        code += "using " + _namesp + "_BLL;//Add reference vao" + vbCrLf
        code += "namespace " + _namesp + vbCrLf + "{" + vbCrLf
        code += vbTab + "public class " + tblName + vbCrLf
        code += vbTab + "{" + vbCrLf
        code += vbTab + vbTab + "private " + _namesp + "_BLL." + tblName + "_BLL obj= new " + _namesp + "_BLL." + tblName + "_BLL();" + vbCrLf
        code += vbTab + vbTab + "// Insert" + vbCrLf
        code += vbTab + vbTab + "#region Insert" + vbCrLf
        code += Insert_GUI()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "// Update" + vbCrLf
        code += vbTab + vbTab + "#region Update" + vbCrLf
        code += Update_GUI()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "// Del" + vbCrLf
        code += vbTab + vbTab + "#region Delete" + vbCrLf
        code += Del_GUI()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "// SelectByID" + vbCrLf
        code += vbTab + vbTab + "#region SelectByID" + vbCrLf
        code += Load_GUI()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "// SelectALL" + vbCrLf
        code += vbTab + vbTab + "#region SelectALL" + vbCrLf
        code += LoadTable_GUI()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "// Load Du Lieu" + vbCrLf
        code += vbTab + vbTab + "string "
        For i = 0 To Leng - 2
            If mData.Rows(i)("Autoval") Is DBNull.Value Then      
                code += ColName(i) + ", "
            End If
        Next
            If mData.Rows(Leng - 1)("Autoval") Is DBNull.Value Then      
            code += ColName(Leng - 1) + ";" + vbCrLf
            End If
        code += vbTab + vbTab + "#region Load Du Lieu" + vbCrLf
        code += Load_DL_GUI()
        'code += BindControl()
        'code += Convert()

        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + "}" + vbCrLf
        code += "}" + vbCrLf + vbCrLf + vbCrLf
        Return code
    End Function

    Public Function GetBLL() As String
        Dim code As String = Header()
        code += "// Khai bao lop" + vbCrLf
        code += "using System;" + vbCrLf
        code += "using System.Collections;" + vbCrLf
        code += "using System.Data;" + vbCrLf
        code += "using " + _namesp + "_Entities;//Add reference vao" + vbCrLf
        code += "using " + _namesp + "_DAL;//Add reference vao" + vbCrLf
        code += "namespace " + _namesp + "_BLL" + vbCrLf + "{" + vbCrLf
        code += vbTab + "public class " + tblName + "_BLL" + vbCrLf
        code += vbTab + "{" + vbCrLf

        code += vbTab + vbTab + "// Ham khoi tao khong tham so" + vbCrLf

        code += vbTab + vbTab + "#region Constructor" + vbCrLf
        code += new1_BLL()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "private " + _namesp + "_DAL." + tblName + "_DAL obj= new " + _namesp + "_DAL." + tblName + "_DAL();" + vbCrLf
        code += vbTab + vbTab + "#region Function" + vbCrLf

        code += vbTab + vbTab + "#region Insert" + vbCrLf
        code += vbTab + vbTab + "// Insert" + vbCrLf
        code += Insert_BLL()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "#region Update" + vbCrLf
        code += vbTab + vbTab + "// Update" + vbCrLf
        code += Update_BLL()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "#region Del" + vbCrLf
        code += vbTab + vbTab + "// Del" + vbCrLf
        code += Del_BLL()
        'code += vbTab + vbTab + "//Get Info"
        'code += Convert()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "#region SelectByID" + vbCrLf
        code += vbTab + vbTab + "// SelectByID" + vbCrLf
        code += Load_BLL()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "#region SelectALL" + vbCrLf
        code += vbTab + vbTab + "// SelectALL" + vbCrLf
        code += LoadTable_BLL()
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        ' Check Exist
        code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf
        code += vbTab + vbTab + "// Dong Class" + vbCrLf
        code += vbTab + "}" + vbCrLf
        code += "}" + vbCrLf + vbCrLf + vbCrLf
        Return code
    End Function

    Public Function GetStore() As String
        Dim code As String = Header1()
        code += "-- InSert" + vbCrLf
        code += Insert_Store()
        code += "-- Update" + vbCrLf
        code += Update_store()
        Return code
    End Function

    Public Function GetMVC() As String
        Dim code As String = Header1()
        code += ClassTable()
        Return code
    End Function


#End Region

#Region "Bind"
    Public Function BindControl() As String
        Dim code As String = ""
        Dim i As Integer

        ' Các biến số
        For i = 0 To Leng - 1
            code += vbTab + vbTab + vbTab + "txt" + ColName(i) + ".Text = " + ColName(i) + ";" + vbCrLf
        Next
        Return code
    End Function
#End Region

#Region "Gen Control"
    Public Function GenControl() As String
        Dim code As String = "<table width=""100%"">" + vbCrLf
        Dim i As Integer

        code += vbTab + "<tr>" + vbCrLf
        code += vbTab + vbTab + "<td></td>" + vbCrLf
        code += vbTab + vbTab + "<td><asp:Label ID=""lblMessage"" runat=""server"" Visible=""false"" Font-Bold=""true"" ForeColor=""red""></asp:Label></td>" + vbCrLf
        code += vbTab + "</tr>" + vbCrLf

        ' Các biến số
        For i = 0 To Leng - 1
            code += vbTab + "<tr>" + vbCrLf
            code += vbTab + vbTab + "<td>" + ColName(i) + "</td>" + vbCrLf
            code += vbTab + vbTab + "<td><asp:TextBox ID=""txt" + ColName(i) + """ runat=""server"" style=""width:300px;""></asp:TextBox></td>" + vbCrLf
            code += vbTab + "</tr>" + vbCrLf
        Next
        code += vbTab + "<tr>" + vbCrLf
        code += vbTab + vbTab + "<td></td>" + vbCrLf
        code += vbTab + vbTab + "<td><asp:Button ID=""btnSave"" runat=""server"" Text=""Save""></asp:Button></td>" + vbCrLf
        code += vbTab + "</tr>" + vbCrLf
        code += "</table>"
        Return code
    End Function
#End Region


#Region "Gencode script oracle"
    Private Function IdentityColumn(ByVal ora() As String) As String
        For i As Integer = 0 To Leng - 1
            If Not mData.Rows(i)("Autoval") Is DBNull.Value Then
                If ora(i) = "NUMBER" Or ora(i) = "INTEGER" Then
                    Return ColName(i)
                End If
            End If
        Next
        Return ""
    End Function

    Private Function OracleDataType() As String()

        Dim ora() As String
        ReDim ora(mData.Rows.Count - 1)

        For i As Integer = 0 To Leng - 1
            ora(i) = "VARCHAR2(250)"
            If ColType(i) = "long" Or ColType(i) = "int" Or ColType(i) = "byte" Or ColType(i) = "bool" Then ora(i) = "INTEGER"
            If ColType(i) = "double" Or ColType(i) = "float" Then ora(i) = "NUMBER"
            If ColType(i) = "datetime" Then ora(i) = "DATE"
        Next

        Return ora
    End Function

    
    Public Function GenOracleScript() As String
        Dim ora() As String = OracleDataType()
        Dim code As String = "--" + tblName.ToUpper + vbCrLf
        code += "CREATE TABLE @@TABLENAME (" + vbCrLf
        For i As Integer = 0 To Leng - 2
            Dim col As String = ColName(i).ToUpper + " " + ora(i).ToUpper

            If (PrimaryKey(i)) Then
                col += " PRIMARY KEY "
            End If

            code += col + "," + vbCrLf
        Next
        code += ColName(Leng - 1).ToUpper + " " + ora(Leng - 1).ToUpper + vbCrLf + ");" + vbCrLf + vbCrLf

        Dim identity As String = IdentityColumn(ora)

        If (Not identity.Equals("")) Then
            code += "CREATE SEQUENCE SEQ_@@TABLENAME" + vbCrLf
            code += "MINVALUE 1" + vbCrLf
            code += "MAXVALUE 999999999999999999" + vbCrLf
            code += "START WITH 1" + vbCrLf
            code += "INCREMENT BY 1" + vbCrLf
            code += "NOCACHE " + vbCrLf
            code += ";" + vbCrLf + vbCrLf


            code += "CREATE OR REPLACE TRIGGER AUTOVAL_@@TABLENAME" + vbCrLf
            code += "BEFORE INSERT ON @@TABLENAME" + vbCrLf
            code += "FOR EACH ROW" + vbCrLf
            code += "BEGIN" + vbCrLf
            code += "IF :new.ID IS NULL THEN" + vbCrLf
            code += vbTab + "Select Case SEQ_SYS_ACTION.nextval" + vbCrLf
            code += vbTab + "INTO :new.@@ID FROM DUAL;" + vbCrLf
            code += "END IF;" + vbCrLf
            code += "END;" + vbCrLf + vbCrLf

            code = code.Replace("@@ID", identity.ToUpper)
        End If
        code = code.Replace("@@TABLENAME", tblName.ToUpper)

        Return code

    End Function
#End Region

#Region "add node"
    Public Function GenAddNodeXML() As String
        Dim code As String = "XmlElement e = doc.CreateElement(""elem"");" + vbCrLf

        For i As Integer = 0 To ColName.Length - 1
            code += "CommonFunction.AddNode(doc, e, """ + ColName(i) + """, dt.Rows[i][""" + ColName(i) + """].ToString());" + vbCrLf
        Next

        Return code
    End Function
#End Region



#Region "Class BO"


    Public Function GetBO() As String
        Dim code As String = Header()
        Dim i As Integer
        code += "// Khai bao lop" + vbCrLf
        code += "using System;" + vbCrLf
        code += "using System.Collections;" + vbCrLf
      code += "using Utilities.Facade;" + vbCrLf
      code += "using Utilities.Model;" + vbCrLf + vbCrLf
      code += "namespace Utilities.Business" + vbCrLf + "{" + vbCrLf
      code += vbTab + "public class " + tblName + "BO : BaseBO" + vbCrLf
      code += vbTab + "{" + vbCrLf

      code += vbTab + vbTab + "private " + tblName + "Facade facade = " + tblName + "Facade.Instance;" + vbCrLf
      code += vbTab + vbTab + "protected static " + tblName + "BO instance = new " + tblName + "BO();" + vbCrLf

      code += vbTab + vbTab + "protected " + tblName + "BO()" + vbCrLf
      code += vbTab + vbTab + "{" + vbCrLf
      code += vbTab + vbTab + vbTab + "this.baseFacade = facade;" + vbCrLf
      code += vbTab + vbTab + "}" + vbCrLf


      code += vbTab + vbTab + "public static " + tblName + "BO Instance" + vbCrLf
      code += vbTab + vbTab + "{" + vbCrLf
      code += vbTab + vbTab + vbTab + "get { return instance; }" + vbCrLf
      code += vbTab + vbTab + "}" + vbCrLf

      code += vbTab + "}" + vbCrLf
      code += "}" + vbCrLf + vbCrLf
      Return code
   End Function


#End Region

#Region "Class Facade"

   Public Function GetFacade() As String
      Dim code As String = Header()
      Dim i As Integer
      code += "// Khai bao lop" + vbCrLf
      code += "using System;" + vbCrLf
      code += "using System.Collections;" + vbCrLf
      code += "using Utilities.Model;" + vbCrLf + vbCrLf
      code += "namespace Utilities.Facade" + vbCrLf + "{" + vbCrLf
      code += vbTab + "public class " + tblName + "Facade : BaseFacade" + vbCrLf
      code += vbTab + "{" + vbCrLf

      code += vbTab + vbTab + "protected static " + tblName + "Facade instance = new " + tblName + "Facade(new " + tblName + "Model());" + vbCrLf

      code += vbTab + vbTab + "protected " + tblName + "Facade(" + tblName + "Model model) : base(model)" + vbCrLf
      code += vbTab + vbTab + "{" + vbCrLf
      code += vbTab + vbTab + "}" + vbCrLf

      code += vbTab + vbTab + "public static " + tblName + "Facade Instance" + vbCrLf
      code += vbTab + vbTab + "{" + vbCrLf
      code += vbTab + vbTab + vbTab + "get { return instance; }" + vbCrLf
      code += vbTab + vbTab + "}" + vbCrLf

      code += vbTab + vbTab + "protected " + tblName + "Facade() : base()" + vbCrLf
      code += vbTab + vbTab + "{" + vbCrLf
      code += vbTab + vbTab + "}" + vbCrLf

      code += vbTab + "}" + vbCrLf
      code += "}" + vbCrLf + vbCrLf
      Return code
   End Function

#End Region

#Region "GetInfo AnhThao"
   Public Function GetInfoAnhThao() As String
      Dim code As String = Header()
      Dim i As Integer
      code += "// Khai bao lop" + vbCrLf
      code += "using System;" + vbCrLf + vbCrLf
      code += "namespace Utilities.Model" + vbCrLf + "{" + vbCrLf
      code += vbTab + "public class " + tblName + "Model : BaseModel" + vbCrLf
      code += vbTab + "{" + vbCrLf
      code += vbTab + vbTab + "// Cac bien so" + vbCrLf
      code += vbTab + vbTab + "#region Vars" + vbCrLf
      For i = 0 To Leng - 1
         code += vbTab + vbTab + "private " + ColType(i) + " _" + ColName(i) + " = " + GetInitValue(ColType(i)) + ";" + vbCrLf
      Next
      code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf


      code += vbTab + vbTab + "#region Property" + vbCrLf
      code += vbTab + vbTab + "// Cac thuoc tinh" + vbCrLf
      For i = 0 To mData.Rows.Count - 1
         code += vbTab + vbTab + "public " + ColType(i) + " " + ColName(i) + vbCrLf
         code += vbTab + vbTab + "{" + vbCrLf
         code += vbTab + vbTab + vbTab + "get{ return _" + ColName(i) + "; }" + vbCrLf

         code += vbTab + vbTab + vbTab + "set{ _" + ColName(i) + " = value; }" + vbCrLf
         code += vbTab + vbTab + "}" + vbCrLf
      Next
      code += vbTab + vbTab + "#endregion" + vbCrLf + vbCrLf

      ' Ðóng Class
      code += vbTab + "}" + vbCrLf
      code += "}" + vbCrLf + vbCrLf + vbCrLf
      Return code
   End Function
#End Region



End Class
